import {Injectable} from '@angular/core';
import {Product} from "./products";
import {HttpClient} from "@angular/common/http";

@Injectable({
  providedIn: 'root'
})
export class CarService {
  // 定义一个 items 属性来存储购物车中当前产品的数组
  items: Product[] = []

  constructor(
    private http: HttpClient
  ) {


  }

  addToCart(product: Product) {
    this.items.push(product);
  }

  getItems() {
    return this.items
  }

  clearCart() {
    return this.items = []
  }

  getShippingPrice() {
    return this.http.get<{
      type: string, price: number
    }[]>('/assets/shipping.json')
  }
}
